package com.dadi.mashangkaixue

/**
 *  author: 韦敏敏
 *  date: 2020/1/31 0031
 *  声明一个泛型类
 */
class Box<T>(t:T) {
    var value = t
}
fun <W> boxIn(value: W) = Box(value)
fun main(args : Array<String>){
    /*var boxInt = Box<Int>(10)
    var boxString = Box<String>("Runoob")
    println(boxInt.value)
    println(boxString.value)*/
/*  val riqi =  boxIn(20200131).value
    val name = boxIn("liaoming").value
    println(riqi)
    println(name)*/
   /* val age = 23
    val name = "runoob"
    val bool = true
    doPrintln(age)   // 整型
    doPrintln(name)  // 字符串
    doPrintln(bool)  // 布尔型*/
/*    sort(listOf(1,2,3))
    sortedSetOf(HashMap<Int, String>())*/
    var strCo : Ruoob<String> = Ruoob("a")
    var anyCo : Ruoob<Any> = Ruoob<Any>("b")
    anyCo = strCo
    println(anyCo.foo()) // 输出a

}
fun <L> doPrintln(content : L){
    when(content){
        is Int -> println("整型数字为 $content")
        is String -> println("字符串转换为大写: ${content.toUpperCase()}")
        else -> println("L 不是整型，也不是字符串")
    }
}
fun <M : Comparable<M>> sort(list: List<M>){
    // ......

}
fun <Z> copyWhenGreater(list: List<Z>, threshold : Z) : List<String>
    where Z : CharSequence,
          Z : Comparable<Z> {
    return list.filter { it > threshold }.map { it.toString() }
}
// 声明处型变
// 定义一个支持协变的类
class Ruoob<out A>(val a : A){
    fun foo() : A {
     return a
    }
}
class LiaoMing<in B>(b : B){
    fun foo( b : B){


    }
}